﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Algorithm_api.calculate;
using Algorithm_api.calculate.Binomial;
using Microsoft.AspNetCore.Cors;
using Algorithm_api.calculate.FractalTree;
using Algorithm_api.calculate.BranchBound;
using Algorithm_api.calculate.twentyfour;
using Algorithm_api.calculate.GeneContrast;
using Algorithm_api.calculate.YachtRentals;
using Algorithm_api.calculate.MapOverlay;
using Algorithm_api.util;
using Algorithm_api.calculate.StrongLine;

namespace Algorithm_api.Controllers
{
    [Route("api/[controller]")]
    [EnableCors("AllowAllOrigins")]
    public class CalculateController : Controller
    {
        // GET api/values
        [HttpGet]
        public BinomialResult Get(int k, int n)
        {
            Binomial bino = new Binomial(k, n);

            return bino.getBinomial();
        }

        [Route("/api/GetFractalTree")]
        [HttpGet]
        public List<Line> GetFractalTree(Line start, double angle, double length, int deep)
        {
            FractalTree tree = new FractalTree(angle, length, deep);
            return tree.GetTree(start);
        }

        [Route("/api/GetBranchBound")]
        [HttpGet]
        public int GetBranchBound(string array, int k)
        {
            var arr = Util.StringToArray(array);
            
            BranchBound bb = new BranchBound()
            {
                N = arr.Length,
                K = k,
                Array = arr,
                List = new int[array.Length+1]
            };
            bb.dfs(0,0);
            return bb.result;
        }

        [Route("/api/Calculate24")]
        [HttpGet]
        public TwentyFourResult Calculate24(double num1,double num2,double num3,double num4)
        {
            double[] nums = new double[] { num1, num2, num3, num4 }; 
            Calculate24 cal = new calculate.twentyfour.Calculate24();
            return cal.Is24(nums);
        }
        
        [Route("/api/GeneContrast")]
        [HttpGet]
        public ContrastResult ContrastGene(string g1, string g2)
        {
            Contrast cons = new Contrast(g1, g2);
            return cons.GeneContrast();
        }

        [Route("/api/Yacht")]
        [HttpGet]
        public YachtResult YachtRentals(string prices, int n)
        {
            var pri = Util.StringToArray(prices);
            Yacht yacht = new Yacht(pri, n);
            return yacht.LowerPrice();
        }

        [Route("/api/MapOverlay")]
        [HttpGet]
        public string[] MapOverlay()
        {
            Overlay overlay = new Overlay();
            return overlay.MapOverlay();
        }

        [Route("/api/StrongLine")]
        [HttpGet]
        public string[] StrongLine(int n)
        {
            MapData md = new MapData();
            MyMap mm = new MyMap();
            return mm.GetStrongLine(md.graphs[n]).ToArray();
        }
        
    }
}
